home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today - The Disc! 5 / CD-ROM Today - The Disc (Issue 5)(November 1994).ISO / mac / Mac shareware / Education / RLaB / rlib / compan.r < prev    next >
Text File  |  1994-09-21  |  929b  |  44 lines

  1. //
  2. // Syntax:    compan ( P )
  3.  
  4. // Description:
  5.  
  6. // Compan(P), where P is an (n+1)-vector, is the n-by-n companion
  7. // matrix whose first row is -P(2:n+1)/P(1). Special case: if P is a
  8. // scalar then compan(P) is the P-by-P matrix compan(1:P+1).
  9.  
  10. //  References:
  11. //  J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University Press,
  12. //       1965, p. 12.
  13. //  C. Kenney and A.J. Laub, Controllability and stability radii for companion
  14. //       form systems, Math. Control Signals Systems, 1 (1988), pp. 239-256.
  15. //       (Gives explicit formulas for the singular values of compan(P).)
  16. //
  17.  
  18. compan = function( P )
  19. {
  20.   local(A, n, p);
  21.  
  22.   n = max(size(P));
  23.  
  24.   // Handle scalar P.
  25.   if( n == 1 )
  26.   {
  27.     n = P+1;
  28.     p = 1:n;
  29.   else
  30.     p = P[:]';    // Ensure p is a row vector.
  31.   }
  32.  
  33.   // Construct matrix of order n-1.
  34.   if( n == 2 )
  35.   {
  36.     A = 1;
  37.   else
  38.     A = diag(ones(1,n-2),-1);
  39.     A[1;] = -p[2:n]/p[1];
  40.   }
  41.  
  42.   return A;
  43. };
  44.